package com.example.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component

public class TimeRecordAspect {
    @Around("@annotation(com.example.aop.aspect.TimeRecord)")
    public Object doAround(ProceedingJoinPoint pjp) {
        long start = System.currentTimeMillis();
        Object result = null;
        try {
            result = pjp.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }finally {
            long cost = System.currentTimeMillis() - start;
            log.info(pjp.getSignature()+"耗时 {}ms",cost);
        }

        return result;
    }

}



























